Imports System.IO
Imports System.Xml
Imports System.Xml.XPath

Public Class SessionResponse
    Inherits Response

#Region "shared"

    Private Shared ReadOnly SESSION_DOC_TYPE As New Dtd("session.dtd", "session")
    'Private Shared ReadOnly XPATH_SESSION_ID As XPathExpression = XPathExpression.Compile("/session")

    Private Shared Function Read(ByVal xr As XmlReader) As String

        'Dim xd As New XPathDocument(xr)
        'Dim xn As XPathNavigator = xd.CreateNavigator()
        'Dim sessionId As String = xn.SelectSingleNode(XPATH_SESSION_ID).Value
        xr.MoveToContent()
        Return xr.ReadString()

    End Function
#End Region

#Region "instance"

    Private _SessionId As String

    Public Sub New(ByVal xml As String)

        MyBase.New(Net.HttpStatusCode.OK)

        'Dim xmlWithoutDtd As String = XmlString.RemoveDocType(xml)
        'SESSION_DOC_TYPE.Validate(xmlWithoutDtd)

        'Dim xr As XmlReader = XmlString.GetXmlReader(xmlWithoutDtd)
        Dim xr As XmlReader = SESSION_DOC_TYPE.GetValidatingReader(xml)
        _SessionId = Read(xr)

    End Sub

    Public Sub New(ByVal input As Stream)

        MyBase.New(Net.HttpStatusCode.OK)

        Dim xr As XmlReader = SESSION_DOC_TYPE.GetValidatingReader(input)
        _SessionId = Read(xr)

    End Sub

    Public ReadOnly Property SessionId() As String
        Get
            Return _SessionId
        End Get
    End Property
#End Region
End Class
